﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IFRS.Models;

namespace IFRS.DataAccess.DAL
{
    public class SPR_SUBSIDYDEPOSIT
    {
        public DataTable SEARCH_ALL(SubsidyDeposit subsidyDeposit, Paging paging,bool isAllBranch,string sCostCenter, ref int iRecordCount)
        {
            DataTable dt;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));

                lstParams.Add(new SqlParameter("@isAllBranch", isAllBranch));
                lstParams.Add(new SqlParameter("@sCostCenter", sCostCenter));

                lstParams.Add(new SqlParameter("@DataTypeID", subsidyDeposit.DataTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@TransactionDate", subsidyDeposit.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@CostCenter", subsidyDeposit.CostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", subsidyDeposit.IsConfirmed.AsDBValue()));

                dt = utility.StoredProcDataTable("SPR_SUBSIDYDEPOSIT_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int subsidyDepositId)
        {
            DataTable dt;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@SubsidyDepositID", subsidyDepositId));
                dt = utility.StoredProcDataTable("SPR_SUBSIDYDEPOSIT_SEARCHBYID", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(SubsidyDeposit subsidyDeposit)
        {
            int iNum;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@SubsidyDepositID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@DataTypeID", subsidyDeposit.DataTypeID));
                lstParams.Add(new SqlParameter("@TransactionDate", subsidyDeposit.TransactionDate));
                lstParams.Add(new SqlParameter("@GLAccount", subsidyDeposit.GLAccount));
                lstParams.Add(new SqlParameter("@CostCenter", subsidyDeposit.CostCenter));
                lstParams.Add(new SqlParameter("@Amount", subsidyDeposit.Amount));
                lstParams.Add(new SqlParameter("@SubsidyDepositValue", subsidyDeposit.SubsidyDepositValue));
                lstParams.Add(new SqlParameter("@IsConfirmed", subsidyDeposit.IsConfirmed));
                lstParams.Add(new SqlParameter("@RP_GSB_PRDCD", subsidyDeposit.RP_GSB_PRDCD));
                lstParams.Add(new SqlParameter("@RP_SOURCE_FILE", subsidyDeposit.RP_SOURCE_FILE));
                lstParams.Add(new SqlParameter("@RP_MAPPING_CD", subsidyDeposit.RP_MAPPING_CD));
                lstParams.Add(new SqlParameter("@CreatedDate", subsidyDeposit.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", subsidyDeposit.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", subsidyDeposit.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", subsidyDeposit.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", subsidyDeposit.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", subsidyDeposit.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", subsidyDeposit.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", subsidyDeposit.UpdatedBranch));

                utility.ExecuteStoredProc("SPR_SUBSIDYDEPOSIT_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(SubsidyDeposit subsidyDeposit)
        {
            int iNum;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@SubsidyDepositID", subsidyDeposit.SubsidyDepositID));
                lstParams.Add(new SqlParameter("@DataTypeID", subsidyDeposit.DataTypeID));
                lstParams.Add(new SqlParameter("@TransactionDate", subsidyDeposit.TransactionDate));
                lstParams.Add(new SqlParameter("@GLAccount", subsidyDeposit.GLAccount));
                lstParams.Add(new SqlParameter("@CostCenter", subsidyDeposit.CostCenter));
                lstParams.Add(new SqlParameter("@Amount", subsidyDeposit.Amount));
                lstParams.Add(new SqlParameter("@SubsidyDepositValue", subsidyDeposit.SubsidyDepositValue));
                lstParams.Add(new SqlParameter("@IsConfirmed", subsidyDeposit.IsConfirmed));
                lstParams.Add(new SqlParameter("@RP_GSB_PRDCD", subsidyDeposit.RP_GSB_PRDCD));
                lstParams.Add(new SqlParameter("@RP_SOURCE_FILE", subsidyDeposit.RP_SOURCE_FILE));
                lstParams.Add(new SqlParameter("@RP_MAPPING_CD", subsidyDeposit.RP_MAPPING_CD));
                lstParams.Add(new SqlParameter("@UpdatedDate", subsidyDeposit.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", subsidyDeposit.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", subsidyDeposit.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", subsidyDeposit.UpdatedBranch));

                iNum = (int)utility.ExecuteStoredProc("SPR_SUBSIDYDEPOSIT_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(SubsidyDeposit subsidyDeposit)
        {
            int iNum;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@SubsidyDepositID", subsidyDeposit.SubsidyDepositID.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", subsidyDeposit.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", subsidyDeposit.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", subsidyDeposit.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", subsidyDeposit.UpdatedBranch.AsDBValue()));

                iNum = (int)utility.ExecuteStoredProc("SPR_SUBSIDYDEPOSIT_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
    }
}
